import { Empty } from 'antd'

export const useFormAdd = ({
  orgOptions,
  handleSearchOrg,
  AppListOptions,
  reset,
  onOrgChange,
  CreateOptions,
}: {
  orgOptions: IOptionItem[]
  handleSearchOrg: (newValue?: string) => void
  AppListOptions: IOptionItem[]
  CreateOptions: IOptionItem[]
  reset: () => void
  onOrgChange: (...set: any) => void
}): IItemArray[] => {
  return [
    {
      name: 'org',
      label: '组织名称',
      type: 'Select',
      placeholder: '请选择组织名称',
      option: orgOptions,
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        labelInValue: true,
        onSearch: handleSearchOrg,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
        onChange: onOrgChange,
        onClear: () => {
          handleSearchOrg()
        },
      },
      rules: [
        {
          required: true,
          message: '请选择组织名称',
        },
      ],
    },
    {
      name: 'app',
      label: '所属应用',
      type: 'Select',
      option: CreateOptions,
      placeholder: '请选择所属应用',
      rules: [
        {
          required: true,
          message: '请选择所属应用',
        },
      ],
      config: {
        labelInValue: true,
      },
    },
    {
      name: 'roleName',
      label: '角色名称',
      type: 'Input',
      placeholder: '请输入角色名称',
      rules: [
        {
          required: true,
          message: '请输入角色名称',
        },
      ],
      config: {
        showCount: true,
        maxLength: 30,
      },
    },
    {
      name: 'roleDesc',
      label: '角色描述',
      type: 'TextArea',
      placeholder: '请输入角色描述',
      rules: [
        {
          required: true,
          message: '请输入角色描述',
        },
      ],
      config: {
        showCount: true,
        maxLength: 100,
      },
    },
  ]
}
export const useFormEdit = ({ detailInfo }: { detailInfo: Record<string, any> }): IItemArray[] => {
  return [
    {
      label: '组织名称',
      type: 'Custom',
      slot: detailInfo?.orgName || '-',
    },
    {
      label: '所属应用',
      type: 'Custom',
      slot: detailInfo?.applicationName || '-',
    },
    {
      name: 'roleName',
      label: '角色名称',
      type: 'Input',
      placeholder: '请输入角色名称',
      config: {
        showCount: true,
        maxLength: 30,
      },
      rules: [
        {
          required: true,
          message: '请输入角色名称',
        },
      ],
    },
    {
      name: 'roleDesc',
      label: '角色描述',
      type: 'TextArea',
      placeholder: '请输入角色描述',
      config: {
        showCount: true,
        maxLength: 100,
      },
      rules: [
        {
          required: true,
          message: '请输入角色描述',
        },
      ],
    },
  ]
}
export const useFormSupplier = ({
  supplierOption,
  isSupplierEdit,
  classIdOptions,
}: {
  supplierOption: IOptionItem[]
  isSupplierEdit: boolean
  classIdOptions: IOptionItem[]
}): IItemArray[] => {
  return [
    {
      name: 'supplier',
      label: '供应商权限',
      type: 'Select',
      option: supplierOption,
      placeholder: '请选择供应商',
      config: {
        mode: 'multiple',
        optionFilterProp: 'label',
        disabled: !isSupplierEdit,
      },
    },
    {
      name: 'classAuthority',
      label: '大类权限',
      type: 'Select',
      option: classIdOptions,
      placeholder: '请选择大类权限',
      config: {
        mode: 'multiple',
        optionFilterProp: 'label',
      },
    },
  ]
}
